﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HalalCheck.Services;
using Xamarin;
using Xamarin.Forms;

namespace HalalCheck.ViewModels
{
    public class LiveMadinaViewModel : BaseViewModel
    {
        private string _urlDrop;


        public string UrlDrop
        {
            get { return _urlDrop; }
            set
            {
                if (value != null)
                {
                    _urlDrop = value;
                    Url = new UrlWebViewSource { Url = _urlDrop };
                    NotifyPropertyChanged();
                }
            }
        }

        private UrlWebViewSource _url;
        public UrlWebViewSource Url
        {
            get { return _url; }
            set
            {
                if (value != null)
                {
                    _url = value;
                }
                NotifyPropertyChanged();
            }
        }

        public LiveMadinaViewModel()
        {
            SetWebViewUrl();
        }

        public async void SetWebViewUrl()
        {
            Dialogs.ShowLoading();
            try
            {
                UrlDrop = await DependencyService.Get<ILiveMadinaService>().GetLiveMadinaUrl();
            }
            catch (Exception e)
            {
                Insights.Report(e);
            }
            finally
            {
                Dialogs.HideLoading();
            }
        }
    }
}
